package com.sdry.approval.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sdry.approval.entity.LeaveMan;
import com.sdry.approval.entity.LeaveRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

/**
 * 请假申请
 * @author chenbin
 * @date 2020年2月21日16:02:02
 * @version 1.0
 */
public interface LeaveRequestMapper extends BaseMapper<LeaveRequest> {

    /**
     * 添加
     * @param userId
     * @param requestId
     */
    @Insert("insert into leave_man(user_id,leave_requert_id,type,request_type) values(#{userId},#{requestId},#{type},#{requestType})")
    void addLeaveMan(@Param("userId") String userId, @Param("requestId") Long requestId,@Param("type") String type,@Param("requestType") String requestType);

    /**
     * 查询所有的审批人员
     * @param requestId
     * @param requestType
     * @return
     */
    @Select("select user_id,request_type,type,leave_requert_id,proposal from leave_man where request_type = #{requestType} and leave_requert_id = #{requestId} and type = 'sp' ")
    List<LeaveMan> queryLeaveManList(Long requestId, String requestType);

    /**
     * 添加意见或建议
     * @param requestType
     * @param requestId
     * @param proposal
     * @param userId
     * @return
     */
    @Update("update leave_man set proposal = #{proposal} where  request_type = #{requestType} and leave_requert_id = #{requestId} and type = 'sp' and user_id = #{userId} ")
    Integer approval(@Param("requestType") String requestType, @Param("requestId") Long requestId, @Param("proposal") String proposal, @Param("userId") Long userId);
}
